import unittest

from enums.modbus_register import InnerDecode
from service.client.modbus_client import ModbusClient


class TestAddDevice(unittest.TestCase):
    def setUp(self):
        self.client = ModbusClient("127.0.0.1", 503)

    def test_write_register(self):
        self.client.write_holding_registers(1, 0, data_type=InnerDecode.FloatABCD.value, value_list=[1, 2, 3])
        print(self.client.get_latest_message())

    def test_write_coil_registers(self):
        for i in range(5):
            self.client.write_single_coil_register(1, 0, [0, 1])
        self.client.write_coil_registers(1, 0, value_list=[0, 1, 0, 1, 1])
        print(self.client.get_latest_message())

    def test_write_coil_register(self):
        self.client.write_single_coil_register(1, 0, [0, 1, 0])

    def test_read_holding_registers(self):
        self.client.read_holding_registers(1, 0, count=10)
        print(self.client.get_latest_message())
